package com.aiju.cash.ui.member.adater;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.aiju.cash.ui.member.entity.Member;
import com.aiju.common.PixValue;
import com.aiju.widgit.layout.SettingItemTextView;

import java.util.List;

/**
 * @author: 佐为
 * @date: 2017-02-21 14:27
 * @version: V1.0
 * @Description: 会员
 */
public class MemberAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<Member> memberCards;

    public MemberAdapter(Context context, List<Member> memberCards) {
        this.context = context;
        this.memberCards = memberCards;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(new SettingItemTextView(context));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder holder1 = (ViewHolder) holder;
        Member member = memberCards.get(position);


        holder1.memberVew.setLeftText(member.getName());
        holder1.memberVew.setRightText(member.getPhone());
        holder1.memberVew.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return memberCards.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private SettingItemTextView memberVew;

        public ViewHolder(View itemView) {
            super(itemView);
            memberVew = (SettingItemTextView) itemView;
            memberVew.getRightView().setTextColor(Color.parseColor("#666666"));
            memberVew.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, PixValue.dp.valueOf(44)));
        }
    }

    //点击事件
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
